import Vue from 'vue'
import VueRouter from 'vue-router'
import Welcome from './components/Welcome.vue'
import Home from "./components/Home.vue"
import Resource from './components/emergencyMap/Resource.vue'
import Site from './components/emergencyMap/Site.vue'
import Label from './components/emergencyMap/Label.vue'
import Login from './components/Login.vue'
import Official from './components/selfStudy/Official.vue'
import Mission from './components/selfStudy/Mission.vue'
import Announcement from './components/announcement/Announcement.vue'
import DataDictionary from './components/dictionary/DataDictionary.vue'

Vue.use(VueRouter)

const router = new VueRouter({
    routes: [{
        path: '/login',
        component: Login,
    }, {
        path: '/',
        component: Home,
        redirect: '/home'

    }, {
        path: '/home',
        component: Home,
        redirect: '/welcome',
        children: [
            { path: '/welcome', component: Welcome },
            { path: '/resource', component: Resource },
            { path: '/site', component: Site },
            { path: '/label', component: Label },
            { path: '/official', component: Official },
            { path: '/mission', component: Mission },
            { path: '/announcement', component: Announcement },
            { path: '/dataDictionary', component: DataDictionary }
        ]
    }]
})

// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
// to 将要访问的路径
// from 代表从哪个路径跳转而来
// next 是一个函数，表示放行  next('/login')  强制跳转
// if (to.path === '/login') return next()
// 获取token
// const tokenStr = window.sessionStorage.getItem('token')
// if (!tokenStr) return window.location = "http://172.17.135.69:8889/"
// next()
// })

export default router